/*
 * @Author: nengwu 409791297@qq.com
 * @Date: 2020-06-29 17:32:52
 * @LastEditors: mylesshie@gmail.com
 * @LastEditTime: 2020-08-15 21:51:25
 * @description:
 */

import React, { useState } from 'react'
import { useDispatch } from 'react-redux'
import { ScrollView, View, Text, SafeAreaView } from 'react-native'
import { Input, Button } from 'react-native-elements'
import { Toast } from 'native-base'
import styles from './styles'
import * as userActions from '@/actions/user'

const Feedback = props => {
  const dispatch = useDispatch()
  const [sugDesc, setSugDesc] = useState('')
  const [phone, setPhone] = useState('')
  const [qq, setQq] = useState('')

  const _onChangeText = (text, type) => {
    if (type === 'sugDesc') {
      setSugDesc(text)
    }
    if (type === 'phone') {
      setPhone(text)
    }
    if (type === 'qq') {
      setQq(text)
    }
  }

  const _submit = () => {
    if (!sugDesc) {
      return Toast.show({
        text: '请输入需要反馈的内容',
        duration: 1500
      })
    }

    dispatch(userActions.submitFeedback(sugDesc, phone, qq)).then(() => {
      Toast.show({
        text: '反馈提交成功，感谢您的支持',
        duration: 1500
      })
      setSugDesc('')
    })
  }

  return (
    <>
      {/* <StatusBar barStyle="dark-content" backgroundColor="#fff"/> */}
      {/* <Headers title="用户反馈" /> */}
      <SafeAreaView style={styles.wrap}>
        <ScrollView
          style={styles.container}
          contentInsetAdjustmentBehavior="automatic"
        >
          <View style={styles.textareaBox}>
            <Input
              value={sugDesc}
              onChangeText={e => _onChangeText(e, 'sugDesc')}
              multiline
              containerStyle={styles.textarea}
              inputContainerStyle={styles.inputContainer}
              inputStyle={styles.inputStyle}
              placeholder="请输入您所遇到的问题"
              placeholderTextColor="#B4B4B4"
            />
          </View>
          <View style={styles.bottomTitleBox}>
            <Text style={styles.bottomTitle}>联系方式</Text>
          </View>
          <View style={styles.formWrap}>
            <View style={styles.formBox}>
              <Input
                placeholder="手机号"
                value={phone}
                onChangeText={e => _onChangeText(e, 'phone')}
              />
            </View>
            <View style={styles.formBox}>
              <Input
                placeholder="QQ"
                value={qq}
                onChangeText={e => _onChangeText(e, 'qq')}
              />
            </View>
          </View>
          <Button
            onPress={_submit}
            buttonStyle={styles.button}
            title="提交"
            titleStyle={styles.buttonText}
          />
        </ScrollView>
      </SafeAreaView>
    </>
  )
}

export default Feedback
